<?php
/**
 * This is the model class for table "tbl_contract_schedule".
 *
 * The followings are the available columns in table 'tbl_contract_schedule':
 * @property integer $id
 * @property integer $contractid
 * @property string $amount
 * @property string $date
 * @property string $invoice
 */
class ContractSchedule extends CActiveRecord{
    /**
	 * Returns the static model of the specified AR class.
	 * @return ContractQuarterly the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
	public function tableName()
        {
            return 'tbl_contract_schedule';
        }

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('contractid, amount, invoice,billtype', 'required'),			
			array('amount', 'length', 'max'=>10),
			array('invoice', 'length', 'max'=>15),
                        array('date','safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, contractid, amount, date, invoice', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
                    'contract'=>array(self::BELONGS_TO,'Contracts','contractid'),
                    'invoiceModel'=>array(self::BELONGS_TO,'Invoice','invoice'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'contractid' => 'Contractid',
			'amount' => 'Amount',
			'date' => 'Date',
			'invoice' => 'Invoice',
                    
		);
	}
        
        public function isInvoiceForScheduleContractCreated(){
       
        
            $exist=Yii::app()->db->createCommand('select count(invoice) from tbl_invoice where invoice=:invoice')
                    ->bindValue('invoice', $this->invoice)->queryScalar();
            
            if($exist>0){
                return true;
            }
        
            return false;
        }
        

}
?>
